<?php

namespace App\Http\Controllers\V1\Api;


use App\Models\V1\Position;

use App\Models\V1\UserPermission;
use Illuminate\Http\Request;


class PositionController extends BaseController
{
    /**
     * 名片列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function List(Request $request)
    {
        $query = Position::query();
        $pageSize = $request->input('pageSize', 10);
        $order = $request->input('order', 'desc');
        $sort = $request->input('sort', 'created_at');
        if ($request->filled('position_class_id')) {
            $query->where('position_class_id', $request->input('position_class_id'));
        } else {
            $query->where('recommend', 1);
        }
        $query->where('state', 1);
        $query->orderBy($sort, $order);
        $data = $query->select('id', 'position_class_id', 'position_name', 'thumb', 'name', 'birth', 'work', 'skill')->paginate($pageSize);
        return ajax_output(200, "成功", $data);
    }


    /**
     * 名片详情-api
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function Info(Request $request)
    {
        $id = $request->input('id', "");
        if (!$id) {
            return ajax_output(300, "名片id不能为空");
        }

        $data = Position::where('id', $id)->first();
        return ajax_output(200, "成功", $data);
    }


    /**
     * 增加联系次数-api
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function Incc(Request $request)
    {
        $id = $request->input('id', "");
        if (!$id) {
            return ajax_output(300, "名片id不能为空");
        }

        $data = Position::where('id', $id)->increment('c_num', 1);;
        return ajax_output(200, "成功", $data);
    }


}
